package com.liuguang.testassert.controller;

import com.alibaba.fastjson.JSONObject;
import com.liuguang.testassert.common.Result;
import com.liuguang.testassert.congfig.MyConfigurationProperties;
import com.liuguang.testassert.congfig.MyPropertySource;
import com.liuguang.testassert.service.TestAssertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConstructorBinding;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @ClassName: TestController
 * @Description：
 * @Author: wanghr
 * Date: 4:55 PM 2020/5/29
 * Version: 1.0
 */
@Api(tags = "测试模块")
@RestController
@RequestMapping("/test")
public class TestController {
    private final static Logger logger = LoggerFactory.getLogger(TestController.class);
    @Autowired
    private TestAssertService testAssertService;

    @Autowired
    private MyConfigurationProperties myConfigurationProperties;

    @Autowired
    private MyPropertySource myPropertySource;

    @ApiOperation(value = "测试", notes = "测试断言")
    @PostMapping("/testAssert")
    public Result<JSONObject> testAssert(@RequestBody JSONObject jsonObject, HttpServletRequest request) {

//        logger.info("request的content-type：{}",request.getContentType());

        Result<JSONObject> result = new Result<>();
//        logger.info("测试断言入参：{}", jsonObject);
//        result = testAssertService.testAssert(jsonObject);
//        logger.info("测试断言出参：{}", result);
        result.setMsg("sdsfsfsfsdf我");
        return result;
    }

    @GetMapping("/testAssert1")
    public Result<JSONObject> testAssert1(HttpServletRequest request) {
        Result<JSONObject> result = new Result<>();
        String contentType = request.getContentType();
        logger.info("11111:{}", contentType);
        StandardMultipartHttpServletRequest req = null;
        try {
            req = (StandardMultipartHttpServletRequest) request;
        } catch (Exception e) {
            logger.info("2222222");
            e.printStackTrace();
        }
        try {
            Map<String, MultipartFile> fileMap = req.getFileMap();
        } catch (Exception e) {
            logger.info("33333333");
            e.printStackTrace();
        }
        if (request instanceof StandardMultipartHttpServletRequest) {

            result.setMsg("sdsfsfsfsdf我");
        }
        return result;
    }

    @GetMapping("/testAssert2")
    public void testAssert2() {
        String name = myConfigurationProperties.getName();
        System.out.println("name = " + name);
    }

    @GetMapping("/testAssert3")
    public void testAssert3() {
        String name = myPropertySource.getName();
        System.out.println("name = " + name);
        Integer num = myPropertySource.getNum();
        System.out.println("num = " + num);
    }

}
